<template>
	<div class="update-birthday">
		<van-datetime-picker
		  v-model="currentDate"
		  type="date"
		  title="选择年月日"
		  :min-date="minDate"
		  :max-date="maxDate"
			@cancel="$emit('close')"
			@confirm="onConfirm"
		/>
	</div>
</template>

<script>
	import { updateUserProfile } from '../../../utils/user.js'
	import dayjs from 'dayjs'
	
	export default {
		name:'updateBirthday',
		props:{
			value: {
				type:String,
				required:true
			}
		},
		data() {
			return {
				 minDate: new Date(1970, 0, 1),
				 maxDate: new Date(2025, 10, 1),
				 currentDate: new Date(this.value),
			}
		},
		methods:{
			async onConfirm() {
				this.$toast.loading({
					message:'保存中',
					forbidclick:true
				})
				await updateUserProfile({
				 	birthday: dayjs(this.currentDate).format('YYYY-MM-DD')
				 })
				  
				 this.$toast.success('保存成功')
				 this.$emit('input',dayjs(this.currentDate).format('YYYY-MM-DD'))
				 
				 this.$emit('close')
				
			}
		}
	}
</script>

<style>
</style>
